<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>模板列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox" id="searchtmplNm">
                <div class="label">模板名称</div>
                <div class="field">
                    <input name="tmplNm" id="tmplNm" type="text" class="ui-textbox" value="${tmplNm}">
                </div>
            </div>
                <div class="fieldBox" id="searchBuOrgCdId">
                <div class="label">所属组织机构</div>
                <div class="field">
                    <select name="buOrgCd" id="buOrgCd">
                        <option value=" " seleted>请选择</option>
                        <c:forEach items="${orgListList }" var="org">
                        	<c:if test="${orgCd == org.key }">
                        		<option value="${org.key }" selected>${org.value }</option>
                        	</c:if>
                        	<c:if test="${orgCd != org.key }">
                        		<option value="${org.key }">${org.value }</option>
                        	</c:if>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn"  class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
               <span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->新增</span>
               <span id="addBtn" onclick="modifyBtn();" class="sq-button sq-button-round">修改</span> 
              
            <!-- <span id="csBtn" onclick="getscore();" class="sq-button sq-button-round">测试</span> 
               <span id="detailBtn" onclick="detailBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>详细</span> 
               <span id="flowStartBtn" class="sq-button sq-button-round" onclick="flowStart();">发起流程</span>-->
               
            </div>

			
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div> 
</div>

<script type="text/javascript">
	var grid = null;
	var queryFlag = '${queryFlag}'; //只查询列表
	var buOrgCd ='${orgCd}';
	$(function () {
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/system/sysscoretmpl/initList.do?buOrgCd='+buOrgCd,
	    	method : 'get',	    	
	        columns: [
	            { display: '模板编号', name: 'tmplCd', minWidth: 140 , enabledSort:true}, 
	            { display: '模板名称', name: 'tmplNm', minWidth: 240,align:'center', enabledSort:true},
	            { display: '所属机构', name: 'orgNm', minWidth: 240,align:'center', enabledSort:true},

	            { display: '常量系数A', name: 'cons', width: 140, enabledSort:true},
	            getOptColumn()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:true,
	        rownumbers:true/* ,
	        onRenderComplete: function () {
	        	iframeResize ();
	        } */
	    });
	 //   initOrgTree();
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	       //  data["crtTm"] = $("#crtTm").val();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	
	    $("#pageloading").hide();
	
	});
	
	//获取操作列
	function getOptColumn(){
		if(queryFlag!="query"){
		var column = {
                display: '操作',
                isSort: false,
                width: 150,
                align:'left',
                render: function (rowdata, rowindex, value){
                	 var h="";
                
                        h='<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                        h+="'"+rowdata.id+"'";
                        h+=')"><i class="sqBtnIco_4"></i>修改</a>'
                        h+='<a class="sq-button-hasicon" href="javascript:removeBtn(';
                        h+="'"+rowdata.id+"'";
                        h+=')"><i class="sqBtnIco_7"></i>删除</a>'
           		
                	/*   h+='<a class="sq-button-hasicon" href="javascript:commShowFlow(';
                      h+="'"+rowdata.pInstId+"'";
                      h+=')"><i class="sqBtnIco_7"></i>查看流程</a>' */
                    return h;
                }
            }
		return column;
		}else{
			var column =  {};
			return column;
		}
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function addBtn(){
		var callback = function(){
			 grid.reload();
		}


		var timestamp=new Date().getTime();
		Add_navTab('tab_tmpl_info_add'+timestamp,'添加模板信息','<%=path%>/system/sysscoretmpl/toTmplAddPage.do',callback);
	}
	function modifyBtn(id){
		var callback = function(){
			 grid.reload();
		}
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		} */
		var fromPrjFlag = true;
		var _flag = $("#fromPrjFlagId").val();//来自哪里
		if(StringUtils.isNotEmpty(_flag)){
			if(_flag == 'false'){
				fromPrjFlag = false;
			}
		}
		//查询参数
		var detailFlag = false;
	//	var params = "?fromPrjFlag="+fromPrjFlag+"&id="+id+"&detailFlag="+detailFlag;
	var params="?Tmplid="+id;
		//如果客户ID存在则加入参数

		//var id = selectedRows[0].id;
		Add_navTab('tab_tmpl_info_add'+id,'修改模板信息','<%=path%>/system/sysscoretmpl/toModifyPage.do'+params,callback);
	}
	//删除所选模板信息
	function removeBtn(id){
		var _ids = [];
			_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
		//	alert('<%=path%>/system/sysscoretmpl/removeTmplById.do?id='+id)
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/system/sysscoretmpl/removeTmplById.do?id='+id,
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
	}
	
	function detailBtn(id){
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		
		var id = selectedRows[0].id; */
		var fromPrjFlag = true;
		var detailFlag = true;
		
		var _flag = $("#fromPrjFlagId").val();//来自哪里
		if(StringUtils.isNotEmpty(_flag)){
			if(_flag == 'false'){
				fromPrjFlag = false;
			}
		}
		
		Add_navTab('tab_project_detail'+id,'模板详情','<%=path%>/system/sysscoretmpl/toModifyPage.do?fromPrjFlag='+fromPrjFlag+'&&Tmplid='+id+'&&detailFlag='+detailFlag);
	}
	//启动流程
	function flowStart(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var modelTyp = FlowConstant.FLOW_MODEL_TYP_PRJ;
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	console.log(json);
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
        		var _id = selectedRows[0].id;
        		$.ajax({
            		type: 'post',
            		dataType:'json',
            		data:{
            			id:_id,
            			procDefKey:json.procDefKey,
            			procDefId:json.procDefId,
            			procNo:json.procNo
            		},
            		url: '<%=path%>/system/sysscoretmpl/addFlowStart.do',
            		success:function(msg){
            			wait_dialog.close();
            			 if(msg.success == 1){
           					 UIUtils.alertSuccessHold1(msg.info);
            				 grid.reload();
            			 }else{
           					 UIUtils.alertErrorHold1(msg.info);
            			 }
            		}
            	});
            }
        });
	}
	
	
	
	
	 //初始化查询条件中的下拉树
  /*var searchOrgTree = null;
    function initOrgTree(){
    	 searchOrgTree = $("#orgCd").ligerComboBox({
             selectBoxWidth: 240,
             selectBoxHeight: 150,
             treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
             tree: {
                 ajaxType: 'get',
                 idFieldName:'text',
                 checkbox: false,
                 parentIcon: "none",
                 childIcon: "none"
             }
         });
    	 
    	 $.ajax({
     		type: 'get',
     		dataType:'json',
     		data: "",
     	//	url: '<%=path%>/system/sysOrg/searchOrgTree.do',
     //		success:function(msg){
     	//		if(msg.success == 1){
     	//			searchOrgTree.treeManager.setData(msg.data);
     	//			searchOrgTree.clear();
     	//		}else{
     	//			 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
     	//		}
     //		}
     //	});
    	 
  //  }
    **/
  function clearBtn(){
    $("#searchBar").ligerForm();
			var form = new liger.get("searchBar");
			//form.clear(); 
			form.setData({
				prjNm:" ",
				cstNm:" ",
				prjTypCd:" ",
				bizTypCd:" ",
				prjStsCd:" ",
				orgCd:" ",
				lsCntNo:" "
			 });
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    }
	}
	
	function getscore(){
        //弹出框校验供应商是否已存在
        $.ligerDialog.SQopen({
            width: 800,
            height:380,
            title : '',
            url:'<%=path%>/system/sysscorerec/toGetPrjScore.do?id=170103077000012',

        });
	}
</script>

</body>
</html>